n, q = map(int, input().split())
s = list(range(n + 1))
d = [0] * (n + 1)  # 记录每个箱子下方的箱子数量
size = [1] * (n + 1)  # 记录以每个节点为根的集合包含的箱子总数

def find_set(x):
    if x != s[x]:
        root = find_set(s[x])  # 先递归找到根节点
        d[x] += d[s[x]]       # 用递归前的父节点距离更新
        s[x] = root           # 路径压缩
    return s[x]

def merge_set(x, y):
    x, y = find_set(x), find_set(y)
    if x != y:
        s[x] = s[y]
        d[x] = size[y]  # 把x移到y上，x下方的箱子数量为y的集合大小
        size[y] += size[x]

for _ in range(q):
    get_num = list(map(int, input().split()))
    if len(get_num) == 3:
        merge_set(get_num[1], get_num[2])
    else:
        find_set(get_num[1])  # 确保路径压缩
        print(d[get_num[1]])